package com.flashextended.apps.logomaker.view.windows.properties.content
{
	import com.flashextended.apps.logomaker.beans.workareaobjects.TextOnStage;
	import com.flashextended.apps.logomaker.singleton.AppControl;
	import com.flashextended.apps.logomaker.singleton.AppLocales;
	import com.flashextended.apps.logomaker.singleton.Fonts;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.containers.VBox;
	import mx.controls.CheckBox;
	import mx.controls.ColorPicker;
	import mx.controls.ComboBox;
	import mx.controls.NumericStepper;
	import mx.controls.VRule;
	import mx.events.ColorPickerEvent;
	import mx.events.ListEvent;
	import mx.events.NumericStepperEvent;
	
	public class TextPropertiesContent extends GenericPropertiesContent
	{
		private var currentSelectedObject:TextOnStage;
		private var cp:ColorPicker;
		private var comboFonts:ComboBox;
		private var fontSizeSteper:NumericStepper;
		
		public function TextPropertiesContent()
		{
			super();
			currentSelectedObject = TextOnStage(AppControl.getInstance().workarea.getReferenceObject());
			this.getCommonMenuContainer().height = 100;
			addTextProperties();
		}
		
		private function cpHandler(e:ColorPickerEvent):void
		{
			currentSelectedObject.fontColor = cp.selectedColor;
		}
		
		private function addTextProperties():void
		{
			var line:VRule = new VRule();
			line.percentHeight = 100;
			this.addChild(line);
			
			var vb:VBox = new VBox();
			vb.percentWidth = 100;
			vb.percentHeight = 100;
			vb.setStyle("verticalGap", 10);
			vb.setStyle("paddingLeft", 6);
			vb.setStyle("paddingTop", 6);			
			
			comboFonts = new ComboBox();
			//comboFonts.width = 80;
			//vb.addChild(buildMenuLabels(comboFonts, AppLocales.getInstance().data.locales["chooseFont"]));
			vb.addChild(buildMenuLabels(comboFonts, ""));	
			var ac:ArrayCollection = new ArrayCollection(new Fonts().getFontsNames());
			comboFonts.dataProvider = ac;
			comboFonts.selectedIndex = currentSelectedObject.fontType;
			comboFonts.addEventListener(ListEvent.CHANGE, fontChangeHandler);
			
			fontSizeSteper = new NumericStepper();
			fontSizeSteper.stepSize = 1;
			fontSizeSteper.minimum = 7;
			fontSizeSteper.maximum = 100;
			fontSizeSteper.value = currentSelectedObject.fontSize;
			fontSizeSteper.addEventListener(NumericStepperEvent.CHANGE, changeFontSizeHandler);
			vb.addChild(buildMenuLabels(fontSizeSteper, AppLocales.getInstance().data.locales["fontSize"]));
			
			cp = new ColorPicker();
			cp.addEventListener(ColorPickerEvent.CHANGE, cpHandler);
			vb.addChild(buildMenuLabels(cp, AppLocales.getInstance().data.locales["textColor"]));
			cp.selectedColor = currentSelectedObject.fontColor;
			
			var cbBold:CheckBox = new CheckBox();
			cbBold.addEventListener(Event.CHANGE, fontBoldHandler);
			
			cbBold.selected = currentSelectedObject.fontBold;
			vb.addChild(buildMenuLabels(cbBold, AppLocales.getInstance().data.locales["fontBold"]));
			
			var cbItalic:CheckBox = new CheckBox();
			cbItalic.addEventListener(Event.CHANGE, fontItalicHandler);
			cbItalic.selected = currentSelectedObject.fontItalic;
			vb.addChild(buildMenuLabels(cbItalic, AppLocales.getInstance().data.locales["fontItalic"]));
			
			var cbUnderline:CheckBox = new CheckBox();
			cbUnderline.addEventListener(Event.CHANGE, fontUnderlineHandler);
			cbUnderline.selected = currentSelectedObject.fontUnderline;
			vb.addChild(buildMenuLabels(cbUnderline, AppLocales.getInstance().data.locales["fontUnderline"]));					
			
			this.addChild(vb);
		}
		
		private function fontChangeHandler(e:ListEvent):void
		{
			currentSelectedObject.fontType = comboFonts.selectedIndex;
		}
		
		private function changeFontSizeHandler(e:NumericStepperEvent):void
		{
			currentSelectedObject.fontSize = fontSizeSteper.value;
		}
		
		private function fontBoldHandler(e:Event):void
		{
			currentSelectedObject.fontBold = CheckBox(e.currentTarget).selected;
		}
		private function fontItalicHandler(e:Event):void
		{
			currentSelectedObject.fontItalic = CheckBox(e.currentTarget).selected;
		}
		private function fontUnderlineHandler(e:Event):void
		{
			currentSelectedObject.fontUnderline = CheckBox(e.currentTarget).selected;
		}				
		
	}
}